package Service;

import java.util.List;

import org.hibernate.Session;
import org.hibernate.Transaction;

import DAO.bookDAO;
import HibernateUtilsforBM.SFactoryGenerator;

/**
 * 书本数据库操作service类
 * @author MacBook
 *
 */
public class bookService {
	//分页查询
	public List pageSelectService(int start,int size){
		Session session = SFactoryGenerator.getSession();
		Transaction tx = session.beginTransaction();
		List list = null;
		try{
			int need = (start-1)*size;
			list = bookDAO.pageSelect(session,need, size);
		}catch (Exception e) {
			// TODO: handle exception
			tx.rollback();
		}finally{
			session.close();
		}
		return list;
	}
	//获取书本总条数
	public int getBookCount(){
		Session session = SFactoryGenerator.getSession();
		Transaction tx = session.beginTransaction();
		int count= -1;
		try{
			count = bookDAO.getBookCount(session);
		}catch (Exception e) {
			// TODO: handle exception
			tx.rollback();
		}finally{
			session.close();
		}
		
		return count;
	}
}
